<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
    <crudOperation :permission="permission">
<!--      <el-button-->
<!--              slot="right"-->
<!--              class="filter-item"-->
<!--              size="mini"-->
<!--              type="danger"-->
<!--              icon="el-icon-remove-outline"-->
<!--              :loading="enable"-->
<!--              @click="crud.enableOrDisable('DISABLE')"-->
<!--              :disabled="crud.selections.length < 1"-->
<!--              v-permission="permission.disable"-->
<!--      >-->
<!--        禁用-->
<!--      </el-button>-->
<!--      <el-button-->
<!--              slot="right"-->
<!--              class="filter-item"-->
<!--              size="mini"-->
<!--              type="success"-->
<!--              icon="el-icon-circle-check"-->
<!--              :loading="able"-->
<!--              :disabled="crud.selections.length < 1"-->
<!--              @click="crud.enableOrDisable('ENABLE')"-->
<!--              v-permission="permission.enable"-->
<!--      >-->
<!--        启用-->
<!--      </el-button>-->
    </crudOperation>
      <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="70px">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="客户名称">
                <el-input v-model="query.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="状态">
                <el-select v-model="query.status" class="filter-item" clearable placeholder="状态" size="small"
                         style="width: 100%" @change="crud.toQuery">
                  <el-option v-for="item in dict.common_status" :key="item.value" :label="item.label"
                             :value="item.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="编码" prop="code">
            <el-input v-model="form.code" />
          </el-form-item>
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name"  />
          </el-form-item>
          <el-form-item label="模块(字典)" prop="model">
            <el-select v-model="form.model" class="filter-item" clearable placeholder="请选择" size="small"
                       style="width: 100%">
              <el-option v-for="item in dict.t_sys_order_code_model" :key="item.value" :label="item.label"
                         :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="前缀" prop="prefix">
            <el-input v-model="form.prefix"  />
          </el-form-item>
          <el-form-item label="后缀"   prop="suffixValue">
            <el-input v-model="form.suffixValue"  />
          </el-form-item>
          <el-form-item label="后缀长度"  prop="suffixLength">
            <el-input v-model="form.suffixLength"  />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="form.status" class="filter-item" clearable placeholder="状态" size="small"
                       style="width: 100%">
              <el-option v-for="item in dict.common_status" :key="item.value" :label="item.label"
                         :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="日期类型" prop="dateType">
            <el-select @change="changeValue()" v-model="form.dateType" class="filter-item" clearable placeholder="请选择" size="small"
                       style="width: 100%">
              <el-option v-for="item in dict.t_sys_order_code_date_type" :key="item.value" :label="item.label"
                         :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="日期值" prop="dateValue"  v-if="form.dateType">
            <el-date-picker
              v-if="form.dateType == 2"
              v-model="form.dateValue"
              type="month"
              style="width: 100%"
              format="yyyyMM"
              value-format="yyyyMM"
              placeholder="选择月">
            </el-date-picker>

            <el-date-picker
              v-if="form.dateType == 3 || form.dateType == '3'"
              v-model="form.dateValue"
              type="year"
              format="yyyy"
              value-format="yyyy"
              style="width: 100%"
              placeholder="选择年">
            </el-date-picker>
            <el-date-picker
              v-if="form.dateType == 1"
              v-model="form.dateValue"
              type="date"
              style="width: 100%"
              format="yyyyMMdd "
              value-format="yyyyMMdd"
              placeholder="选择日期">
            </el-date-picker>
<!--            <el-input v-model="form.dateValue"  onkeyup="value=value.replace(/[^\d]/g,'')" />-->
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" stripe @cell-dblclick="row=>crud.toEdit(row)" border v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60" />
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('id')" prop="id" label="id" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="编码" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('name')" prop="name" label="名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('seq')" prop="seq" label="排序" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('model')" prop="model" label="模块(字典)" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('status')" label="状态" prop="status" width="75px">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 0" type="danger">禁用</el-tag>
            <el-tag v-else type="success">启用</el-tag>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('dateValue')" prop="dateValue" label="日期值" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('prefix')" prop="prefix" label="前缀" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('suffixValue')" prop="suffixValue" label="后缀" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('suffixLength')" prop="suffixLength" label="后缀长度" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateUserName')" prop="updateUserName" label="修改人名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateTime')" prop="updateTime" label="修改时间" />
        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','sysOrderCode:edit','sysOrderCode:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSysOrderCode from '@/api/system/sysOrderCode'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '系统单据编号', url: 'api/appSysOrderCode', sort: 'id,desc',  optShow: {
    add: true,
    edit: true,
    del: true,
    download: false,
    leadingIn: false,
    enable: true,
    disable: true
  }, crudMethod: { ...crudSysOrderCode }})
const defaultForm = { id: null, code: null, name: null, type: null, model: null, prefix: null, dateType: null, dateValue: null, suffixLength: null, suffixValue: null, seq: null, status: null, remark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null }
export default {
  name: 'SysOrderCode',
  // 主页操作栏显示哪些按钮
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  // 设置数据字典
  dicts: ['common_status','t_sys_order_code_date_type','t_sys_order_code_model'],
  data() {
    return {

      permission: {
        add: ['admin', 'sysOrderCode:add'],
        edit: ['admin', 'sysOrderCode:edit'],
        del: ['admin', 'sysOrderCode:del'],
        import: ['admin', 'sysOrderCode:import'],
        export: ['admin', 'sysOrderCode:export'],
        copy: ['admin', 'sysOrderCode:copy'],
        upload: ['admin', 'sysOrderCode:upload'],
        download: ['admin', 'sysOrderCode:download'],
        enable: ['admin', 'sysOrderCode:enable'],
        disable: ['admin', 'sysOrderCode:disable'],
      },
      rules: {
        code: [
          { required: true, message: '编码不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '状态不能为空', trigger: 'blur' }
        ],
        dateType: [
          { required: true, message: '日期类型不能为空', trigger: 'blur' }
        ],
        dateValue: [
          { required: true, message: '日期值不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        model: [
          { required: true, message: '模块(字典)不能为空', trigger: 'blur' }
        ],
      }
    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      this.form.dateValue = form.dateValue + ''
    },
    changeValue(){
      this.form.dateValue = null
    }
  }
}
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
